<?php
namespace app\admin\controller;

use think\Db;
use think\Controller;
use think\Session;

class Index extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
    public function login()
    {
        $data = input("post.");
        
        $data = [
            'adminName' => input('adminName'),
            'adminPass' => md5(input('adminPass')),
        ];
        $res = Db::name("admin")->where($data)->find();

        if (!$res) {
            $this->error('账户密码错误');
        } else {
            Session::set("adminId", $res["adminId"]);
            Session::set("adminName", $res["adminName"]);
            Session::set("admin", $res["admin"]);
            $this->redirect("user/userlist");
        }
    }
    public function logout(){
        Session::clear();
        $this->redirect("index/index");
    }
}
